home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 November / MACPOWER-1997-11.ISO.7z / MACPOWER-1997-11.ISO / Apple関連 / ResEdit 2.1.3 / Examples / PExamples / Source / ICON.Pick.p < prev    next >
Text File  |  1994-09-14  |  5KB  |  167 lines

  1. {
  2.  COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
  3.  All rights reserved
  4. }
  5.  
  6. UNIT IconPick;
  7.  
  8. { Icon Resource Picker }
  9.  
  10. { This is the Icon resource picker example.
  11.     The general scheme is that a List structure is created whose cells
  12.     contain the ID's of this resource type.  A drawproc is installed in the List
  13.     record which is called to display the resource. }
  14.  
  15. INTERFACE
  16.  
  17. USES    MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
  18.             ResEd;
  19.  
  20. TYPE
  21.     IconPickPtr = ^IconPickRec;
  22.     IconPickHandle = ^IconPickPtr;
  23.  
  24.     IconPickRec = RECORD
  25.             father:                 ParentHandle;{ Back ptr to dad }
  26.             fName:                     STR255;
  27.             wind:                     WindowPtr;    { Picker window }
  28.             rebuild:                 BOOLEAN;
  29.             spare:                    BOOLEAN;
  30.             windowType:         PossibleWindowTypes;
  31.             theResType:         ResType;        { Type of the resource being picked or edited. }
  32.             theResFile:            INTEGER;        { The home resfile of the window. }
  33.             codeResID:             INTEGER;        { Resource ID of the RSSC resource containing the picker or editor. }
  34.             spare1:                    Handle;            { Not used here}
  35.  
  36.             rType:                     ResType;        { Type for picker - could be different from theResType }
  37.             rSize:                     LONGINT;        { Size of a null resource }
  38.             minWindowWidth:    INTEGER;        { Used when the window is grown. }
  39.             minWindowHeight:INTEGER;
  40.             instances:            ListHandle;    { List of instances }
  41.             nInsts:                 INTEGER;        { Number of instances }
  42.             viewBy:                    ViewTypes;    { Current view type }
  43.             showAttributes: BOOLEAN;        { Show attrs in window?    }
  44.             ldefType:                ResType;        { Which LDEF to use }
  45.             theViewMenu:        MenuHandle;    { The picker view menu }
  46.             viewMenuMask:     LONGINT;        { Which items are enabled? }
  47.             cellSize:                Cell;                { Cell size for special view. }
  48.             iconMenu:             Menuhandle; { our menu }
  49.     END;
  50.  
  51. PROCEDURE EditBirth(thing: Handle; dad: ParentHandle);
  52. PROCEDURE PickBirth(t: ResType; dad: ParentHandle);
  53. PROCEDURE DoEvent(VAR evt: EventRecord; pick: IconPickHandle);
  54. PROCEDURE DoInfoUpdate(oldID, newID: INTEGER; pick: PickHandle);
  55. FUNCTION  IsThisYours (thing: Handle; pick: PickHandle): BOOLEAN;
  56. PROCEDURE DoMenu(menu, item: INTEGER; pick: IconPickHandle);
  57.  
  58. IMPLEMENTATION
  59.  
  60. CONST
  61.     iconMenuID = 10;            { This just uses one of ResEdit's menus. }
  62.     
  63.     listCellSizeH = $38;
  64.     listCellSizeV = $42;
  65.     
  66.     { Needs to be 2 wide so that I can always tell a 2d list from a normal text list. }
  67.     minIconsPerRow = 2;
  68.     ICONMinWindowWidth = (minIconsPerRow * listCellSizeH) + theScrollBar;
  69.     ICONMinWindowHeight = listCellSizeV;
  70.  
  71. {$R-}
  72.  
  73. PROCEDURE EditBirth(thing: Handle; dad: ParentHandle);
  74.  
  75. BEGIN
  76. END;
  77.  
  78. { *********************************************************************************** }
  79.  
  80. PROCEDURE PickBirth(t: ResType; dad: ParentHandle);
  81.  
  82. VAR
  83.     pick: IconPickHandle;
  84.     theIconMenu: Menuhandle;         { our menu }
  85.  
  86. BEGIN
  87. pick := IconPickHandle(NewHandle(SIZEOF(IconPickRec)));
  88.  
  89. WITH pick^^ DO
  90.     BEGIN
  91.     father := dad;                                         { Back ptr to dad }
  92.     rType := t;                                             { Resource type }
  93.     viewBy := viewBySpecial;
  94.     ldefType := t;
  95.     cellSize.h := listCellSizeH;
  96.     cellSize.v := listCellSizeV;
  97.     minWindowWidth := ICONMinWindowWidth;
  98.     minWindowHeight := ICONMinWindowHeight;
  99.     END;
  100. IF NOT DoPickBirth(noColor, TRUE, graphical2DPicker, ResEdId, PickHandle(pick)) THEN
  101.     DisposHandle (Handle(pick))
  102. ELSE
  103.     BEGIN            { Setup the snd menu }
  104.     theIconMenu := GetMenu (iconMenuId);
  105.     DetachResource (Handle(theIconMenu));    { Get our own copy. }
  106.     pick^^.iconMenu := theIconMenu;
  107.     END;
  108. END;
  109.  
  110. { *********************************************************************************** }
  111.  
  112. { Everything is taken care of for us by PickEvent.}
  113. PROCEDURE DoEvent(VAR evt: EventRecord; pick: IconPickHandle);
  114.  
  115. BEGIN
  116. PickEvent(evt, PickHandle(pick));
  117. IF evt.what = activateEvt THEN
  118.     BEGIN
  119.     IF ODD(evt.modifiers) THEN
  120.         InsertMenu(pick^^.iconMenu, 0)
  121.     ELSE
  122.         DeleteMenu(iconMenuId);
  123.     DrawMBarLater (FALSE);
  124.     END;
  125. END;
  126.  
  127. { *********************************************************************************** }
  128.  
  129. { Everything is taken care of for us by PickInfoUp }
  130. PROCEDURE DoInfoUpdate(oldID, newID: INTEGER; pick: PickHandle);
  131.  
  132. BEGIN
  133. PickInfoUp(oldID, newID, pick);
  134. END;
  135.  
  136. { *********************************************************************************** }
  137.  
  138. FUNCTION IsThisYours (thing: Handle; pick: PickHandle): BOOLEAN;
  139.  
  140. BEGIN
  141. IsThisYours := FALSE;
  142. END;
  143.  
  144. { *********************************************************************************** }
  145.  
  146. PROCEDURE DoMenu(menu, item: INTEGER; pick: IconPickHandle);
  147.  
  148. BEGIN
  149. IF menu = iconMenuId THEN
  150.     BEGIN
  151.     { Do something with the menu}
  152.     END
  153. ELSE
  154.     BEGIN
  155.     IF (menu = fileMenu) & (item = closeItem) THEN
  156.         BEGIN
  157.         DeleteMenu(iconMenuId);
  158.         DrawMBarLater (FALSE);
  159.     
  160.         DisposHandle (Handle(pick^^.iconMenu));
  161.         END;
  162.     PickMenu(menu, item, PickHandle(pick));
  163.     END;
  164. END;
  165.  
  166. END.
  167.